import 'package:flutter/material.dart';
import 'package:card_swiper/card_swiper.dart';
import 'package:flutter_douban/main_page/home/h5_detail_page/activity_detail_page.dart';
import 'package:flutter_douban/model/banner_model.dart';
import 'package:flutter_douban/tool_views/xuan.dart';

class BannerView extends StatefulWidget {
  final List<BannerModel> bannerList;

  const BannerView({Key? key, required this.bannerList}) : super(key: key);

  @override
  _BannerViewState createState() => _BannerViewState();
}

class _BannerViewState extends State<BannerView> {
  @override
  Widget build(BuildContext context) {
    if (widget.bannerList.length > 0) {
      return Swiper(
        itemCount: widget.bannerList.length,
        autoplay: true,
        itemBuilder: (BuildContext context, int index) {
          return InkWell(
            child: Image.network(
              widget.bannerList[index].i!,
              fit: BoxFit.cover,
            ),
            onTap: (){
              Navigator.of(context).push(MaterialPageRoute(builder: (_) {
                return ActivityDetail(
                  url: widget.bannerList[index].url,
                  titleStr: widget.bannerList[index].t,
                );
              }));
            },
          );
        },

        /// 横线样式
        pagination: SwiperPagination(
          ///指示器显示的位置 Alignment.bottomCenter 底部中间
          alignment: Alignment.bottomCenter,
          /// 距离调整
          margin: const EdgeInsets.only(bottom: 5),
          /// 指示器构建
          builder: RectSwiperPaginationBuilder(
            color: Colors.grey,
            activeColor: Colors.white,
            size: Size(18, 8),
            activeSize: Size(18,8)
          ),
        ),

        /// 圆点样式
        //   DotSwiperPaginationBuilder(
        //     /// 点之间的间隔
        //       space: 2,
        //       /// 没选中时的大小
        //       size: 6,
        //       /// 选中时的大小
        //       activeSize: 12,
        //       /// 没选中时的颜色
        //       color: Colors.black54,
        //       ///选中时的颜色
        //       activeColor: Colors.white)

        // control:
        //     new SwiperControl(color: Colors.red, disableColor: Colors.white),

        onTap: (index) {},
      );
    } else {
      return Image.network(
        'http://i1.douguo.net/upload/note/3/f/6/3fcf8572e8e67e9e0c02f5eb4416ad26.jpg',
        fit: BoxFit.cover,
      );
    }
  }
}
